package cn.yunlang.zhangZhongFei.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import cn.yunlang.zhangZhongFei.entity.Company;
import cn.yunlang.zhangZhongFei.service.CompanyService;
import cn.yunlang.zhangZhongFei.vo.response.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/Company")
@Api(tags = "公司信息")
public class CompanyController {

  @Resource private CompanyService companyService;

  @ApiOperation("分页查")
  @GetMapping("/page")
  public R<IPage<Company>> page(
      @ApiParam(value = "页码", required = true) @RequestParam Integer pageNo,
      @ApiParam(value = "每页大小", required = true) @RequestParam Integer pageSize,
      @ApiParam(value = "公司名称", required = false) @RequestParam(required = false)
          String companyName) {
    return companyService.pageCompany(pageNo, pageSize, companyName);
  }

  @GetMapping("/one")
  @ApiOperation("根据Id查一条")
  public R<Company> one(@RequestParam Long companyId) {
    return companyService.getOne(companyId);
  }

  @PostMapping("/add")
  @ApiOperation("新增")
  public R<String> add(@RequestBody Company company) {
    return companyService.addCompany(company);
  }

  @GetMapping("/delete")
  @ApiOperation("删除")
  public R<String> delete(@RequestParam Long companyId) {
    return companyService.deleteCompany(companyId);
  }

  @PostMapping("/update")
  @ApiOperation("修改")
  public R<String> update(@RequestBody Company company) {
    return companyService.updateCompany(company);
  }
}
